class ConditionsController < ApplicationController
  def index
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    @condition_pages, @conditions = paginate :conditions, :per_page => 10
  end

  def show
    @condition = Condition.find(params[:id])
  end

  def new
    @condition = Condition.new()
  end

  def create
    params[:condition][:locale] = session[:currentUser].locale
    @condition = Condition.new(params[:condition])
    if @condition.save
      flash[:notice] = 'Condition was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    @condition = Condition.find(params[:id])
  end

  def update
    params[:condition][:locale] = session[:currentUser].locale
    @condition = Condition.find(params[:id])
    if @condition.update_attributes(params[:condition])
      flash[:notice] = 'Condition was successfully updated.'
      redirect_to :action => 'show', :id => @condition
    else
      render :action => 'edit'
    end
  end

  def destroy
    Condition.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
end
